<template>
  <el-image class="installTxt" :src="img" fit="cover" @click="openPwaTip" />
</template>

<script setup>
import { ref, defineExpose, onMounted } from "vue";

const img = require("@/assets/installTxt.png");
const deferredPrompt = ref(null);
onMounted(() => {
  // 初始化 pwa安装
  window.addEventListener("beforeinstallprompt", function (e) {
    // 将事件返回存储起来
    deferredPrompt.value = e;
    // 取消默认事件
    e.preventDefault();
    return false;
  });
});
// 初始化 pwa安装
function openPwaTip() {
  if (deferredPrompt.value != null) {
    // 异步触发横幅显示
    deferredPrompt.value.prompt();
  }
}
</script>

<style lang="scss" scoped>
.installTxt {
  width: 100%;
}
</style>>